//
//  HomeTableViewController.m
//  Location_Demo
//
//  Created by JXH on 2021/1/13.
//

#import "HomeTableViewController.h"
#import "LocationManager.h"

@interface HomeTableViewController ()

/** 数据*/
@property (nonatomic, strong) NSMutableArray *dataArray;

@end

@implementation HomeTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.dataArray = [NSMutableArray arrayWithArray:@[@"开启定位收集",@"停止定位收集",@"手动上传定位信息"]];
    
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"HomeTableViewController"];
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 30)];
    
    LocationManager.sharedManager.block = ^(double latitude, double longitude, NSString *address) {
      
        label.text = address;
        NSLog(@"LocationManager.sharedManager address:%@",address);
    };
    
    self.tableView.tableHeaderView = label;
}

#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HomeTableViewController" forIndexPath:indexPath];
    
    cell.textLabel.text = self.dataArray[indexPath.row];
    
    return cell;
}
#pragma mark - -------------- delegate -----------------
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    NSInteger index = indexPath.row;
    
    switch (index) {
        case 0://开启收集
            [LocationManager start];
            break;
        case 1://停止收集
            [LocationManager stop];
            break;
        case 2://手动上传
            [LocationManager upload];
            break;
        default:
            break;
    }
    
}

@end
